Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear pending (un)installs when installers are deleted #23427

Merged
merged 9 commits into from
Oct 31, 2024

Conversation

iansltx
Copy link
Member

@iansltx iansltx commented Oct 31, 2024

For unreleased bug #23350, introduced because we're no longer cascade-deleting all related installs (related to #22996, #21654, #22087)

Checklist for submitter

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • Added/updated tests
  • Manual QA for all new/changed functionality

…ending (un)installs on installer delete

TODO:

* Apply to bulk installer changes
* Update tests to ensure that pending (un)installs get deleted
Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 36 lines in your changes missing coverage. Please review.

Project coverage is 63.15%. Comparing base (471d38b) to head (b289060).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
server/datastore/mysql/software_installers.go 66.03% 24 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23427      +/-   ##
==========================================
+ Coverage   63.13%   63.15%   +0.02%     
==========================================
  Files        1555     1556       +1     
  Lines      147093   147290     +197     
  Branches     3725     3669      -56     
==========================================
+ Hits        92861    93019     +158     
- Misses      46886    46910      +24     
- Partials     7346     7361      +15     
Flag Coverage Δ
backend 64.00% <66.66%> (+0.02%) ⬆️
frontend 52.43% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iansltx
Copy link
Member Author

iansltx commented Oct 31, 2024

@noahtalerman for copy, how does this look? Slight tweak from design review to maintain existing "deleting the installer won't uninstall from all hosts" verbiage:

image

@iansltx iansltx marked this pull request as ready for review October 31, 2024 19:22
@iansltx iansltx requested review from a team as code owners October 31, 2024 19:22
@@ -18,13 +18,15 @@ const DELETE_SW_INSTALLED_DURING_SETUP_ERROR_MSG =
interface IDeleteSoftwareModalProps {
softwareId: number;
teamId: number;
software: any; // TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set this to ISoftwarePackage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just pass in the name as a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have to tweak upstream because according to the type checker we might (but in reality won't) have a VPP app instead, which would result in an undefined installer property, so I can't tighten the type up without other changes (type checker shows ISoftwarePackage | undefined).

The Edit Software modal has the same issue, so probably makes sense to hit both with the same fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way usually handle that is by setting the type as a union with undefined, then use optional chaining to handle the undefined case (which we know won't happen) when referencing it. You could also nullish coallesce to a default case for comfort, though since we know it will always be defined it should be okay either way, of course. So something like

software: ISoftwarePackage | undefined;
...

software?.name ?? "this software"

I'll sometimes leave a comment to the effect of "This will actually always be defined" just to be clear, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have quite a few instances of this situation, which is of course not ideal, but very often cleaning up the typing upstream would involve a) untangling a huge mess of spaghetti and/or b) refactoring our API service layer with generics (something we've discussed) to have actual type checking there. Both would be great to do, but of course, require time, effort, and prioritization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobshandling Revised to pass the (nullable) name of the package in b289060

@iansltx
Copy link
Member Author

iansltx commented Oct 31, 2024

Tests pass on this, including new tests, but I still need to manually QA. Added @lucasmrod for BE review, @RachelElysia for FE review, so if my self-QA passes (will write up test plan on the parent ticket) I can get this merged and cherry-picked later today.

jacobshandling
jacobshandling previously approved these changes Oct 31, 2024
@@ -18,13 +18,15 @@ const DELETE_SW_INSTALLED_DURING_SETUP_ERROR_MSG =
interface IDeleteSoftwareModalProps {
softwareId: number;
teamId: number;
software: any; // TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just pass in the name as a string?

hsi.status = :software_status_install_pending`,
`SELECT
COUNT(*) c
FROM host_software_installs hsi
WHERE hsi.host_id = :host_id AND
WHERE hsi.host_id = :host_id AND hsi.software_installer_id IS NOT NULL AND
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix for the bug reported by QA wolf right? Should the other changes be linked to different issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underlying cause for the QAWolf bug is that we now need to manually clean up pending installs when installers get deleted, rather than the pending installs getting deleted automatically due to the ON DELETE CASCADE that was previously on host_software_installs.software_installer_id. This fix is belt-and-suspenders so the apparent problem goes away in QAWolf's environment without either a migration or a manual DB query, but without the larger cleanup we'd have invisible pending (un)installs when an installer is deleted, and the install part is a regression from v4.58.0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, #23350 exists because the implementation of #21654 was incomplete, so this is unreleased whichever way we slice this.

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@iansltx iansltx merged commit 8258d48 into main Oct 31, 2024
26 checks passed
@iansltx iansltx deleted the 22350-upcoming-activities-fix branch October 31, 2024 23:04
iansltx added a commit that referenced this pull request Oct 31, 2024
For unreleased bug #23350, introduced because we're no longer
cascade-deleting _all_ related installs (related to #22996, #21654,
#22087)

# Checklist for submitter

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
iansltx added a commit that referenced this pull request Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants